import os
from ctypes import windll
from colorama import Fore, Back, Style, init
from function.EthSwitch import EthSwitch
import sys
from function.Log import Log, INFO, WARNNING, CMD, ERROR


ascii_pic = " _____  ___  _____  ___  ___  __  \n" + \
"  \_   \/ _ \/__   \/___\/___\/ /   \n" + \
"   / /\/ /_)/  / /\//  ///  // /   \n" + \
"/\/ /_/ ___/  / / / \_// \_// /___ \n" + \
"\____/\/      \/  \___/\___/\____/ \n"


def is_admin():
    """获取管理员权限

    Returns:
        _type_: _description_
    """
    try:
        return windll.shell32.IsUserAnAdmin()
        # return True
    except:
        return False


if __name__ == "__main__":
    if is_admin():
        init(autoreset=True)
        es = EthSwitch()

        print(Fore.GREEN + ascii_pic)
        Log(True, "gn", "{} 以管理员模式启动！".format(INFO))
        Log(True, "gn", "\n模式选择:  {}[1] 手动设置  [2] 自动设置  [3] 网卡恢复DHCP\n\n".format(Fore.YELLOW, Fore.RESET))
        init(autoreset=True)
        option = input("选项输入 >>>>>>>>> ")
        if option == "1":
            es.run_manual()
        elif option == "2":
            es.run_auto()
        elif option == "3":
            es.run_DHCP()
    else:
        if sys.version_info[0] == 3:
            windll.shell32.ShellExecuteW(None, "runas", sys.executable, __file__, None, 1)

    os.system("pause")